import { createStore } from 'vuex'
import user from './modules/user'
import app from './modules/app'

const store = createStore({
  modules: {
    user,
    app
  },

  state: {
    // 全局状态
  },

  mutations: {
    // 全局mutations
  },

  actions: {
    // 全局actions
  },

  getters: {
    // 全局getters
    token: state => state.user.token,
    userInfo: state => state.user.userInfo,
    roles: state => state.user.roles || [],
    isLoggedIn: state => !!state.user.token,
    isAdmin: state => (state.user.roles || []).includes('ADMIN'),
    isTeacher: state => (state.user.roles || []).includes('TEACHER'),
    isStudent: state => (state.user.roles || []).includes('STUDENT')
  }
})

export default store
